﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StyleMVVM.UnitTests.TestClasses.ValidationObjects;
using StyleMVVM.DependencyInjection;
using StyleMVVM.Validation;
#if NETFX_CORE
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;

#else
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endif

namespace StyleMVVM.UnitTests.Validation
{
	[TestClass]
	public class NestedValidationTests : BaseTestClass
	{
		[TestMethod]
		public void NestedAttributeValidationObjectTest()
		{
			NestedAttributeValidationObject testObject = new NestedAttributeValidationObject();

			IValidationContext validationContext =
				Container.Locate<IValidationService>().GetValidationContext(testObject);

			Assert.AreEqual(ValidationState.InvalidRequired, validationContext.State);
			Assert.AreEqual(1, validationContext.RuleResults().Count());

			testObject.SimpleValidationObject = new SimpleValidationObject();

			Assert.AreEqual(ValidationState.Invalid, validationContext.State);
			Assert.AreEqual(3, validationContext.RuleResults().Count());

			testObject.SimpleValidationObject.TestInt = 2;

			Assert.AreEqual(ValidationState.InvalidRequired, validationContext.State);
			Assert.AreEqual(1, validationContext.RuleResults().Count());

			testObject.SimpleValidationObject.Name = "Hello";

			Assert.AreEqual(ValidationState.Valid, validationContext.State);

			testObject.SimpleValidationObject.Name = null;

			Assert.AreEqual(ValidationState.InvalidRequired, validationContext.State);
			Assert.AreEqual(1, validationContext.RuleResults().Count());

			testObject.SimpleValidationObject = new SimpleValidationObject();

			Assert.AreEqual(ValidationState.Invalid, validationContext.State);
			Assert.AreEqual(3, validationContext.RuleResults().Count());

			testObject.SimpleValidationObject.TestInt = 2;

			Assert.AreEqual(ValidationState.InvalidRequired, validationContext.State);
			Assert.AreEqual(1, validationContext.RuleResults().Count());

			testObject.SimpleValidationObject = null;

			Assert.AreEqual(ValidationState.InvalidRequired, validationContext.State);
			Assert.AreEqual(1, validationContext.RuleResults().Count());
		}
	}
}